package com.tstudy.laoshibang.share;

import com.tencent.tauth.IUiListener;
import com.tencent.tauth.UiError;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

@SuppressWarnings("unused")
public class BaseUIListener implements IUiListener {
	private Context mContext;
	private String mScope;
	private boolean mIsCaneled;
	public static final int ON_COMPLETE = 0;
	public static final int ON_ERROR = 1;
	public  static final int ON_CANCEL = 2;
	private Handler mHandler;
	
	public BaseUIListener(Context mContext) {
		super();
		this.mContext = mContext;
	}

	
	public BaseUIListener(Context mContext,Handler handler,String mScope) {
		super();
		this.mContext = mContext;
		this.mScope = mScope;
		this.mHandler = handler;
	}
	
	public void cancel() {
		mIsCaneled = true;
	}


	@Override
	public void onComplete(Object response) {
		if (mIsCaneled) return;
	    Message msg = mHandler.obtainMessage();
	    msg.what = ON_COMPLETE;
	    msg.obj = response;
	    mHandler.sendMessage(msg);
	}

	@Override
	public void onError(UiError e) {
		if (mIsCaneled) return;
	    Message msg = mHandler.obtainMessage();
        msg.what = ON_ERROR;
        msg.obj = e;
        mHandler.sendMessage(msg);
	}

	@Override
	public void onCancel() {
		if (mIsCaneled) return;
	    Message msg = mHandler.obtainMessage();
        msg.what = ON_CANCEL;
        mHandler.sendMessage(msg);
	}

	public Context getmContext() {
		return mContext;
	}

	public void setmContext(Context mContext) {
		this.mContext = mContext;
	}

}
